//@author A0080440U
//
// **********
//
// add class adds tasks to 2 places
//		the vector of tasks
//		the txt storage
//
// **********

#include "Add.h"


Add::Add(void) {

}


Add::~Add(void) {

}

string Add::execute(Task task, vector<Task> & store) {
	ofstream writeFile;
	writeFile.open(FILENAME_LOGGER.c_str(), ofstream::out | ofstream::app);
	writeFile << "Attempting to add" << endl;
	writeFile.close();
	
	string data;
	Parser parse;
	Storage storage;
	// catching errors
	if(task.getTaskName() == EMPTY) {
		throw exception("add error, no taskname");
	}
	
	// store in vector
	store.push_back(task);

	// store in txt file
	data = parse.convertToString(task);
	storage.addTask(data);
	
	
	// for UI feedback
	data ="added '";
	data += task.getTaskName();
	data += "'";
	
	return data;
}